解题思路:
本题是根据给定的字符串数组中删除串长大于某个值的右边字符串。
第一处:函数的定义,试题中已用M作为字符串的长度,所以应填:M。
第二处:利用while循环,分别对字符串数组中的每个字符串置字符串结束符,程序中已经给定了N个字符串,所以应填:N。
第三处:置字符串结束符,所以应填:0(或’\0’)。
***************************************************
给定程序MODI1.C中函数fun的功能是:根据以下公式求π值,并作为函数值返回。
例如,给指定精度的变量eps输入0.0005时,应当输出Pi=3.140578。
π 1 1 2 1 2 3 1 2 3 4
─=1+ ─ + ─×─ + ─×─×─ + ─×─×─×─+……
2 3 3 5 3 5 7 3 5 7 9
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
给定源程序:
#include
#include
double fun(double eps)
{ double s,t; int n=1;
s=0.0;
t=0;
while( t>eps)
{ s+=t;
t=t * n/(2*n+1);
n++;
}
return(s);
}
main()
{ double x;
printf("\nPlease enter a precision: "); scanf("%lf",&x);
printf("\neps=%lf, Pi=%lf\n\n",x,fun(x));
}